package com.cardvalue.sys.base;

import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.cardvalue.sys.R;

/**
 * Created by cardvalue on 2016/3/30.
 */
public class BaseFragment extends Fragment{

    public ProgressDialog dialog;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        dialog=new ProgressDialog(getActivity());
    }

    /**
     * headFieldIds显示内空的资源id
     * 设置顶部文字显示，顺序为［文字左，文字中，文字右，图片左，图片中，图片右］，不显示可传入0
     * @param
     * */
    protected void setHeaderFields(int... headFieldIds) {
        final int fieldIds[] = { R.id.tv_left, R.id.tv_center, R.id.tv_right,
                R.id.iv_left, R.id.iv_center, R.id.iv_right };
        for (int i = 0; i < headFieldIds.length; i++) {
            if (headFieldIds[i] == 0) {
                continue;
            }
            if (i <= 2) {
                if(getView() == null){
                    Log.e("TAG", "不要在Fragment#onCreateView中调用方法setHeaderFields");
                    return;
                }
                View view = getView().findViewById(fieldIds[i]);
                if (view instanceof TextView) {
                    TextView tv = (TextView) view;
                    tv.setVisibility(View.VISIBLE);
                    tv.setText(getString(headFieldIds[i]));
                }
            } else {
                if(getView() == null){
                    Log.e("TAG", "不要在Fragment#onCreateView中调用方法setHeaderFields");
                    return;
                }
                View view = getView().findViewById(fieldIds[i]);
                if (view instanceof ImageView) {
                    ImageView iv = (ImageView) view;
                    iv.setVisibility(View.VISIBLE);
                    iv.setImageResource(headFieldIds[i]);
                }
            }
        }
    }
}
